﻿using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using static MrPP.SerriedCabinet.CabinetGroup;

namespace MrPP.SerriedCabinet
{
    /*
    public class CheckBoxManager : GDGeek.Singleton<CheckBoxManager>
    {


        [SerializeField]
        private BoxManager _manager;

        public BoxManager manager
        {
            get
            {
                return _manager;
            }
        }
       
        Dictionary<string, ItemData> table_ = new Dictionary<string, ItemData>();
        internal void setup(CabinetGroup.ItemData[] datas)
        {

            foreach (var item in table_)
            {
                var cell =_manager.getCell(item.Value.location);
                if (cell) { 
                    cell.check.all = new List<ItemData>();
                }
            }   
            table_.Clear();
            Dictionary<BoxLocation, List<ItemData>> map = new Dictionary<BoxLocation, List<ItemData>>();
            foreach (var data in datas) {
                if (!map.ContainsKey(data.location)) {
                    map.Add(data.location, new List<ItemData>());
                }
                map[data.location].Add(data);
              
                table_.Add(data.sn, data);
            }

            foreach (var item in map) {
                Cell cell = _manager.getCell(item.Key);
                if (cell != null) {
                    cell.check.all = item.Value;
                }

            }
        }
      
        private List<string> _last = new List<string>();
        internal void check(List<string> list)
        {
           
            List<string> other = list.Except(_last).ToList();
            foreach (string sn in other) {
                ItemData data  = this.getData(sn);
                if (!string.IsNullOrEmpty(data.sn)) {
                    Cell cell = _manager.getCell(data.location);
                    Debug.LogError(data.sn);
                    cell.check.addChecked(data);
                    _last.Add(data.sn);
                }
            }


        }

        private ItemData getData(string sn)
        {
            if (table_.ContainsKey(sn)) {
                return table_[sn];
            }
            return new ItemData();
        }
    }*/
}